window.onload = function(){
	document.getElementById("test").onclick=function(){
		var s = test1();
		drawbingzhuangtu(s[0],s[1],s[2],s[3],s[4]);
	}
	// document.getElementById("test1").onclick = function () {
	// 	test1();
	// }
}
function drawbingzhuangtu(A,B,C,D,E){
	var canvas=document.getElementById("bingzhuangtu");
	canvas.width="400";
	canvas.height="300";
	if(!canvas.getContext){
		return;
	}
	var ctx=canvas.getContext("2d");
	//绘制饼状图，默认的数据，即360度的圆弧表述为Math.PI*2
	drawbing(200,150,150,0,Math.PI*2*A/(A+B+C+D+E),false,"rgb(255,0,0)",ctx);
	drawbing(200,150,150,Math.PI*2*A/(A+B+C+D+E),Math.PI*2*(A+B)/(A+B+C+D+E),false,"rgb(0,255,0)",ctx);
	drawbing(200,150,150,Math.PI*2*B/(A+B+C+D+E),Math.PI*2*(B+C)/(A+B+C+D+E),false,"rgb(17, 52, 128)",ctx);
	drawbing(200,150,150,Math.PI*2*C/(A+B+C+D+E),Math.PI*2*(C+D)/(A+B+C+D+E),false,"rgb(128, 41, 105)",ctx);
	drawbing(200,150,150,Math.PI*2*D/(A+B+C+D+E),Math.PI*2*(D+E)/(A+B+C+D+E),false,"rgb(0, 41, 105)",ctx);

}
//locationx和locationy分别代表圆心坐标x，y，r代表半径，begin和end代表起始弧度和终止弧度，label代表绘制方式
//color代表填充色，ctx代表canvas对象，即画布
function drawbing(locationx,locationy,r,begin,end,label,color,ctx){
	ctx.beginPath();
	ctx.fillStyle=color;
	ctx.moveTo(locationx,locationy);
	ctx.arc(locationx,locationy,r,begin,end,label);
	ctx.fill();
}

function test1() {
	var A=0;
	var B=0;
	var C=0;
	var D=0;
	var E=0;

	// var v1 = document.getElementById("v1").value;
	// var v2 = document.getElementsByTagName("input:text");
	// alert(v2);

	//获取ID为cargetdate下面的input为text的ID和value，如果是页面所有的input则将document.getElementById("cargetdate")换为document即可
	var list=document.getElementsByTagName("input");

	var strData="";
	//对表单中所有的input进行遍历
	for(var i=0;i<list.length && list[i];i++)
	{
		//判断是否为文本框
		if(list[i].type=="text"&&list[i].id!="subEmail")
		{
			if(list[i].value < 60){
				E++;
			}else if (list[i].value >= 60 && list[i].value < 70){
				D++;
			}else if (list[i].value >= 70 && list[i].value < 80){
				C++;
			}else if (list[i].value >= 80 && list[i].value < 90){
				B++;
			}else {
				A++;
			}
			// strData +=list[i].id + list[i].value;
		}
	}
	alert(A+" "+B +" " +C +" "+D + " "+E);
	strData[0]=A;
	strData[1]=B;
	strData[2]=C;
	strData[3]=D;
	strData[4]=E;
	return strData;
}